package com.fengwk.support.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.reflect.MethodSignature;

import com.fengwk.support.exception.BaseException;

public class SpringAspectUtils {
	
	private SpringAspectUtils() {
		throw new BaseException("can not instance " + getClass());
	}
	
	public static <A extends Annotation> A getAnnotation(JoinPoint joinPoint, Class<A> annotationClass) throws BaseException {
		Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    	A annotation = method.getAnnotation(annotationClass);
    	if(annotation == null) {
    		annotation = method.getDeclaringClass().getDeclaredAnnotation(annotationClass);
    	}
    	if(annotation == null) {
    		throw new BaseException();
    	}
    	return annotation;
    }
	
}
